//
//  Mmanager.swift
//  MobileRTCSwiftSample
//
//  Created by zhangheng on 2019/6/20.
//  Copyright © 2019 Zoom Video Communications, Inc. All rights reserved.
//

import Foundation

class Mmanager: NSObject {
    
    class func checkComp(suess:ResultIsSuccess?,fail:os_block_t?){
        let params:[String:Any] = ["version":AppInfo.majorVersion(),"type":"mac"]
        NetworkTool.requestData(type: .post, URLString: mt_url_update, parameters: params, finishCallback: { (result) in
            if let dict = result as? [String : Any] {
                if let data = dict["data"] as? NSDictionary {
                    if let version = data["version"] as? String {
                        let isok = AppInfo.majorVersion().isOlder(than: version)
                        if suess != nil {
                            suess!(isok, dict)
                        }
                    }
                }
            }
            
        }) { (result) in
            if fail != nil {
                fail!()
            }
            GToast.show(msg: "获取数据失败，检查您的网络，刷新请重试！".localized())
        }
    }
    
    class func versionCompUpdate()  {
        let params:[String:Any] = ["version":AppInfo.majorVersion(),"type":"mac"]
        NetworkTool.requestData(type: .post, URLString: mt_url_update, parameters: params, finishCallback: { (result) in
            if let data = (result as! NSDictionary)["data"] as? NSDictionary {
                if let version = data["version"] as? String,let message = data["message"] as? String,let url = data["url"] as? String{
                    let isok = AppInfo.majorVersion().isOlder(than: version)
                    if isok == true {
                        VersionManager.versionUpdate(msg: message, version: version,url: url)
                    }
                }
            }
            
        }) { (result) in
            GToast.show(msg: "获取数据失败，检查您的网络，刷新请重试！".localized())
        }
    }
    
    
    class func checkAnnouce() {
        NetEngine.requstAnnouce(success: { (result) in
            let mode = AnnouceMode.deserialize(from: result)
            if let message = mode?.message {
                let url = mode?.url == "" ? nil:mode?.url
                if message != UserInfoManager.shared.lastAonnouce {
                    let controlelr = URAnnouceViewContoller.init(info: AonnouceInfo.init(message: message, url: url))
                    NSWindow.init(contentViewController: controlelr).lorderFront(nil)
                    UserInfoManager.shared.lastAonnouce = message
                }
            }
            /*
            if let url = mode?.url {
                if let ur = URL.init(string: url) {
                    NSWorkspace.shared.open(ur)
                }
            }
            */
        }, fail: nil)
    }
}
